<template>
	<v-container>
	<div class="text-center ma-2">
  	</div>
	<v-form>
		<div class="headline text-center">{{ $t("login") }}</div>
		<div class="body-2  text-center">
			使用利佳管理账号
		</div>
    <v-container>
      <v-row>
        <v-col cols="12">
          <v-text-field
            label="手机号码"
						v-model="phone"
            outlined
          ></v-text-field>

						<v-text-field
							type="password"
							label="密码"
							v-model="password"
							outlined
						></v-text-field>
					</v-col>

					<v-col class="" cols="12">
						<v-btn v-on:click="login" width="100%" color="success">登陆</v-btn>
					</v-col>
					<v-col class="" cols="12" v-if="iswechat">
						<v-btn v-on:click="wxoauth" width="100%" color="error">微信登陆（暂时不支持）</v-btn>
					</v-col>
				</v-row>
			<v-row>

      </v-row>
    </v-container>
  </v-form>
	</v-container>
</template>

<script>
import { StaffLogin, oauthlogin } from './../../api/api';
export default {
	created:function(){
		// this.$store
		this.$store.commit('setProgress',false)
		// this.iswechat = (function(){return navigator.userAgent.toLowerCase().indexOf('micromessenger') !== -1})();
	},
	data: () => ({
		phone:'',
		password:'',
		itac:'',
		snackbar: {
			isOpen:false,
			text:'',
			type:'error'
		},
		iswechat:false
	}),
  name: 'GoogleLogin',
  props: {
    msg: String
	},
	methods: {
		wxoauth: function(){
			// this.$router.push('/oauth/wechat')
		},
		login: function (event){		
			StaffLogin(this.phone,this.password,this.itac).then((resp)=>{
				console.log(resp)
				var res = resp.data;
				if (res.code == 1){
					this.$store.state.authtoken = res.authtoken;
					this.snackbar = {
							isOpen: true,
							text: "登陆成功",
						}
					console.log(res.authtoken)
					this.$cookies.set("authtoken", res.authtoken) 
					this.$cookies.set("authexp", Math.round(new Date() / 1000)+1600)
					this.$router.push('/staff/workorder/list')
				}else{
					this.$store.commit('setAlert',{icon:'close',text:res.msg,show:true})
					this.snackbar = {
						isOpen: true,
						text: res.msg
					}
				}
			})
		},
	},
}
</script>

<!-- Add "scoped" attribute to limit CSS to this component only -->
<style scoped>
.loginbtn {
	min-width: 88px;
}
.link {
	color:#1a73e8;
}
</style>
